﻿using System.Collections.Generic;

namespace Snake.Gameplay
{
    public class GameplayAbilitiesContainer
    {
        public GameplayAbilityComponent Owner { get; }

        private readonly Dictionary<string, GameplayAbilitySpec> _abilitySpecs =
            new Dictionary<string, GameplayAbilitySpec>();

        public GameplayAbilitiesContainer(GameplayAbilityComponent owner)
        {
            Owner = owner;
        }

        public void GiveAbility(GameplayAbility ability, int level = 1)
        {
            var spec = GameplayFactory.CreateAbilitySpec(ability);
            spec.Container = this;
            _abilitySpecs.Add(ability.abilityTag, spec);
            spec.OnGiven();
        }

        public void OnUpdate(float dt)
        {
            foreach (var spec in _abilitySpecs.Values)
            {
                spec.OnUpdate(dt);
            }
        }
    }
}